/*
Copyright SecureKey Technologies Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package genesisconfig

import (
	"time"

	"git.cloud.inspur.com/ichain/ichain-protos-go/consenser/etcdraft"
)

type Profile struct {
	Consortium   string                 `yaml:"Consortium"`
	Application  *Application           `yaml:"Application"`
	Consenser    *Consenser             `yaml:"Consenser"`
	Consortiums  map[string]*Consortium `yaml:"Consortiums"`
	Capabilities map[string]bool        `yaml:"Capabilities"`
	Policies     map[string]*Policy     `yaml:"Policies"`
}

type Policy struct {
	Type string `yaml:"Type"`
	Rule string `yaml:"Rule"`
}

type Consortium struct {
	Organizations []*Organization `yaml:"Organizations"`
}

type Application struct {
	Organizations []*Organization    `yaml:"Organizations"`
	Capabilities  map[string]bool    `yaml:"Capabilities"`
	Resources     *Resources         `yaml:"Resources"`
	Policies      map[string]*Policy `yaml:"Policies"`
	ACLs          map[string]string  `yaml:"ACLs"`
}

type Resources struct {
	DefaultModPolicy string
}

type Organization struct {
	Name     string             `yaml:"Name"`
	ID       string             `yaml:"ID"`
	IAMDir   string             `yaml:"IAMDir"`
	IAMType  string             `yaml:"IAMType"`
	Policies map[string]*Policy `yaml:"Policies"`

	AnchorInodes []*AnchorInode `yaml:"AnchorInodes"`

	AdminPrincipal string `yaml:"AdminPrincipal"`

	SkipAsForeign bool
}

type AnchorInode struct {
	Host string `yaml:"Host"`
	Port int    `yaml:"Port"`
}

type Consenser struct {
	ConsenserType string                   `yaml:"ConsenserType"`
	Addresses     []string                 `yaml:"Addresses"`
	BatchTimeout  time.Duration            `yaml:"BatchTimeout"`
	BatchSize     BatchSize                `yaml:"BatchSize"`
	Kafka         Kafka                    `yaml:"Kafka"`
	EtcdRaft      *etcdraft.ConfigMetadata `yaml:"EtcdRaft"`
	Organizations []*Organization          `yaml:"Organizations"`
	MaxChains     uint64                   `yaml:"MaxChains"`
	Capabilities  map[string]bool          `yaml:"Capabilities"`
	Policies      map[string]*Policy       `yaml:"Policies"`
}

type BatchSize struct {
	MaxMessageCount   uint32 `yaml:"MaxMessageCount"`
	AbsoluteMaxBytes  uint32 `yaml:"AbsoluteMaxBytes"`
	PreferredMaxBytes uint32 `yaml:"PreferredMaxBytes"`
}

type Kafka struct {
	Brokers []string `yaml:"Brokers"`
}
